package net.shopxx.controller.admin;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import net.shopxx.Message;
import net.shopxx.Message.Type;
import net.shopxx.pager.Pageable;
import net.shopxx.service.TaobaoCollectService;
import net.shopxx.service.TaobaoProductService;

/**
 * Controller - 淘宝宝贝相关操作
 * 
 * @author frankie
 * @version 3.0
 */
@Controller("adminTaobaoProductController")
@RequestMapping("/admin/taobao_product")
public class TaobaoProductController extends BaseController {
	
	@Resource(name = "taobaoProductServiceImpl")
	private TaobaoProductService taobaoProductService;
	
	@Resource(name = "taobaoCollectServiceImpl")
	private TaobaoCollectService taobaoCollectService;
	

	/**
	 * 列表
	 */
	@RequestMapping(value = "/doCollect", method = RequestMethod.POST)
	public String doCollect(String ids, RedirectAttributes redirectAttributes) {
		//FIXME 时间间隔限制
		taobaoCollectService.doCollect(ids);
		addFlashMessage(redirectAttributes, new Message(Type.success,"采集程序正在后台进行中！请稍后查看！"));
		return "redirect:list.jhtml";
	}
	
	/**
	 * 列表
	 */
	@RequestMapping(value = "/doConvert", method = RequestMethod.POST)
	public String doConvert(RedirectAttributes redirectAttributes) {
		//FIXME 时间间隔限制
		taobaoCollectService.doConvert();
		addFlashMessage(redirectAttributes, new Message(Type.success,"采集程序正在后台进行中！请稍后查看！"));
		return "redirect:list.jhtml";
	}
	
	/**
	 * 列表
	 */
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String list(Pageable pageable, ModelMap model) {
		model.addAttribute("page", taobaoProductService.findPage(pageable));
		return "/admin/taobao_product/list";
	}
	
	/**
	 * 列表
	 */
	@RequestMapping(value = "/collect", method = RequestMethod.GET)
	public String add(ModelMap model) {
		return "/admin/taobao_product/collect";
	}

}
